package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SaleReturn;
import com.ruoyi.system.service.ISaleReturnService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 退货管理Controller
 * 
 * @author ruoyi
 * @date 2024-05-08
 */
@RestController
@RequestMapping("/system/return")
public class SaleReturnController extends BaseController
{
    @Autowired
    private ISaleReturnService saleReturnService;

    /**
     * 查询退货管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:return:list')")
    @GetMapping("/list")
    public TableDataInfo list(SaleReturn saleReturn)
    {
        startPage();
        List<SaleReturn> list = saleReturnService.selectSaleReturnList(saleReturn);
        return getDataTable(list);
    }

    /**
     * 导出退货管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:return:export')")
    @Log(title = "退货管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SaleReturn saleReturn)
    {
        List<SaleReturn> list = saleReturnService.selectSaleReturnList(saleReturn);
        ExcelUtil<SaleReturn> util = new ExcelUtil<SaleReturn>(SaleReturn.class);
        util.exportExcel(response, list, "退货管理数据");
    }

    /**
     * 获取退货管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:return:query')")
    @GetMapping(value = "/{stuffId}")
    public AjaxResult getInfo(@PathVariable("stuffId") Long stuffId)
    {
        return success(saleReturnService.selectSaleReturnByStuffId(stuffId));
    }

    /**
     * 新增退货管理
     */
    @PreAuthorize("@ss.hasPermi('system:return:add')")
    @Log(title = "退货管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SaleReturn saleReturn)
    {
        return toAjax(saleReturnService.insertSaleReturn(saleReturn));
    }

    /**
     * 修改退货管理
     */
    @PreAuthorize("@ss.hasPermi('system:return:edit')")
    @Log(title = "退货管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SaleReturn saleReturn)
    {
        return toAjax(saleReturnService.updateSaleReturn(saleReturn));
    }

    /**
     * 删除退货管理
     */
    @PreAuthorize("@ss.hasPermi('system:return:remove')")
    @Log(title = "退货管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{stuffIds}")
    public AjaxResult remove(@PathVariable Long[] stuffIds)
    {
        return toAjax(saleReturnService.deleteSaleReturnByStuffIds(stuffIds));
    }
}
